﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModTrain
{
    public partial class TrainList : System.Web.UI.Page
    {
        TrainBiz trainBiz = new TrainBiz();
        string empCode = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["EmpCode"] != null)
                empCode = Request.Params["EmpCode"].ToString();
            if (!IsPostBack)
            {
                new DepartmentBiz().InitDropDownList(ddlDeptID, "0");
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('TrainAdd.aspx',800,550);");
                if (empCode != "")
                {
                    txtSerWord.Text = empCode;
                    BondData(empCode, "", "", "");
                }
            }
        }
        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string deptName = ddlDeptID.SelectedItem.Text.Trim();

            if (serWord == "" && bTime == "" && eTime == "" && deptName == "")
            {
                JSUtility.Alert(this, "至少输入一个查询条件");
                return;
            }
            if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            {
                JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
                return;
            }
            BondData(serWord, deptName, bTime, eTime);


        }

        private void BondData(string serWord, string deptName, string bTime, string eTime)
        {
            DataTable dt = trainBiz.GetLists(serWord, deptName, bTime, eTime);
       
            if (dt.Rows.Count > 0)
            {
                lbAmount.Text = "合计:    " + dt.Rows.Count; }
            else
            {
                lbAmount.Text = "";
            }
                gvList.DataSource = dt;
                gvList.DataBind();
           
        }
      
        
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            //ExcelUtility.GridViewToExcel(gvList, "TrainList.xls");
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string deptName = ddlDeptID.SelectedItem.Text.Trim();
            ExcelUtility.ExportDsToXls(this,trainBiz.GetLists(serWord, deptName, bTime, eTime), "TrainList.xls");

        }
        //增加信息
        protected void btnAdd_Click(object sender, EventArgs e)
        {

        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }
    }
}